package com.app.megaprosoft.DB;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Types;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.app.megaprosoft.general.DateTime;
import com.app.megaprosoft.general.Number;

public class ServicePOS {
	// DB
	Connect con = new Connect(); 
    Connection conn = con.Connect();
    ResultSet rs = null;
	
    DateTime DateTime =new DateTime();
    
    SQLiteDBClass myDb;
    SQLiteDatabase db;
    Context context;
    private static final String TABLE_ServicePOS = "_ServicePOS";
    private static final String TABLE_ServicePOSLists = "_ServicePOSLists";
    
	// POS
	private String POSOID,
			      UsrOpt,
			      IsActive,
			      IsDeleted,
			      DocNo,
			      ArOID,
			      UserOID,
			      DocDateTime,
			      CompanyOID,
			      SaleType,
			      ArType,
			      RefDocNo,
			      PayableDateTime,
			      
			      DocumentStatus,
			      BalanceStatus;
	
	private double 	TotalAmount, 
					DiscountAmount,
					ReceiveMoney,
					NetTotalAmount;
		    		  
	// POS Lists
	private String 	POSListsOID,
				  	ItemOID, 
				  	UnitOID,
				  	WHOID,
				  	ICZoneOID,
				  	ICStorageOID,
				  	ICShelfOID,
				  	ICColumnOID,
				  	StkInOutDateTime,
				  	Status,
				  	IsMove,
					SerialNo,
					LotNo,
					RefOID,
				    IsItemPromotionGiveaways = "0",
				    IsItemPromotionSets = "0";
	
	private int 	Qty;
	private double 	Price;
	
	
	//Parameter
	private String ParamOID;
	private String ParamDocNo;
	private String ParamPOSOID;
	private String ParamAr;
	private String ParamSDate,ParamEDate;
	private String ParamDocS;
	
	//Get , Set
	
	public String getPOSOID() {
		return POSOID;
	}

	public String getParamDocS() {
		return ParamDocS;
	}

	public void setParamDocS(String paramDocS) {
		ParamDocS = paramDocS;
	}

	public String getParamSDate() {
		return ParamSDate;
	}

	public void setParamSDate(String paramSDate) {
		ParamSDate = paramSDate;
	}

	public String getParamEDate() {
		return ParamEDate;
	}

	public void setParamEDate(String paramEDate) {
		ParamEDate = paramEDate;
	}

	public String getParamAr() {
		return ParamAr;
	}

	public void setParamAr(String ParamAr) {
		this.ParamAr = ParamAr;
	}

	public String getParamPOSOID() {
		return ParamPOSOID;
	}

	public void setParamPOSOID(String paramPOSOID) {
		ParamPOSOID = paramPOSOID;
	}

	public String getRefDocNo() {
		return RefDocNo;
	}

	public void setRefDocNo(String refDocNo) {
		RefDocNo = refDocNo;
	}

	public String getPayableDateTime() {
		return PayableDateTime;
	}

	public void setPayableDateTime(String payableDateTime) {
		PayableDateTime = payableDateTime;
	}

	public String getArType() {
		return ArType;
	}

	public void setArType(String arType) {
		ArType = arType;
	}

	public void setPOSOID(String pOSOID) {
		POSOID = pOSOID;
	}

	public String getUsrOpt() {
		return UsrOpt;
	}

	public void setUsrOpt(String usrOpt) {
		UsrOpt = usrOpt;
	}

	public String getIsActive() {
		return IsActive;
	}

	public void setIsActive(String isActive) {
		IsActive = isActive;
	}

	public String getIsDeleted() {
		return IsDeleted;
	}

	public void setIsDeleted(String isDeleted) {
		IsDeleted = isDeleted;
	}

	public String getDocNo() {
		return DocNo;
	}

	public void setDocNo(String docNo) {
		DocNo = docNo;
	}

	public String getArOID() {
		return ArOID;
	}

	public void setArOID(String arOID) {
		ArOID = arOID;
	}

	public String getUserOID() {
		return UserOID;
	}

	public void setUserOID(String userOID) {
		UserOID = userOID;
	}

	public String getDocDateTime() {
		return DocDateTime;
	}

	public void setDocDateTime(String docDateTime) {
		DocDateTime = docDateTime;
	}

	public String getCompanyOID() {
		return CompanyOID;
	}

	public void setCompanyOID(String companyOID) {
		CompanyOID = companyOID;
	}

	public String getSaleType() {
		return SaleType;
	}

	public void setSaleType(String saleType) {
		SaleType = saleType;
	}

	public double getTotalAmount() {
		return TotalAmount;
	}

	public void setTotalAmount(double totalAmount) {
		TotalAmount = totalAmount;
	}

	public double getDiscountAmount() {
		return DiscountAmount;
	}

	public void setDiscountAmount(double discountAmount) {
		DiscountAmount = discountAmount;
	}

	public double getReceiveMoney() {
		return ReceiveMoney;
	}

	public void setReceiveMoney(double receiveMoney) {
		ReceiveMoney = receiveMoney;
	}

	public double getNetTotalAmount() {
		return NetTotalAmount;
	}

	public void setNetTotalAmount(double netTotalAmount) {
		NetTotalAmount = netTotalAmount;
	}

	public String getDocumentStatus() {
		return DocumentStatus;
	}

	public void setDocumentStatus(String documentStatus) {
		DocumentStatus = documentStatus;
	}

	public String getBalanceStatus() {
		return BalanceStatus;
	}

	public void setBalanceStatus(String balanceStatus) {
		BalanceStatus = balanceStatus;
	}

	public String getPOSListsOID() {
		return POSListsOID;
	}

	public void setPOSListsOID(String pOSListsOID) {
		POSListsOID = pOSListsOID;
	}

	public String getItemOID() {
		return ItemOID;
	}

	public void setItemOID(String itemOID) {
		ItemOID = itemOID;
	}

	public int getQty() {
		return Qty;
	}

	public void setQty(int qty) {
		Qty = qty;
	}

	public double getPrice() {
		return Price;
	}

	public void setPrice(double price) {
		Price = price;
	}

	public String getUnitOID() {
		return UnitOID;
	}

	public void setUnitOID(String unitOID) {
		UnitOID = unitOID;
	}

	public String getWHOID() {
		return WHOID;
	}

	public void setWHOID(String wHOID) {
		WHOID = wHOID;
	}

	public String getICZoneOID() {
		return ICZoneOID;
	}

	public void setICZoneOID(String iCZoneOID) {
		ICZoneOID = iCZoneOID;
	}

	public String getICStorageOID() {
		return ICStorageOID;
	}

	public void setICStorageOID(String iCStorageOID) {
		ICStorageOID = iCStorageOID;
	}

	public String getICShelfOID() {
		return ICShelfOID;
	}

	public void setICShelfOID(String iCShelfOID) {
		ICShelfOID = iCShelfOID;
	}

	public String getICColumnOID() {
		return ICColumnOID;
	}

	public void setICColumnOID(String iCColumnOID) {
		ICColumnOID = iCColumnOID;
	}

	public String getStkInOutDateTime() {
		return StkInOutDateTime;
	}

	public void setStkInOutDateTime(String stkInOutDateTime) {
		StkInOutDateTime = stkInOutDateTime;
	}

	public String getStatus() {
		return Status;
	}

	public void setStatus(String status) {
		Status = status;
	}

	public String getIsMove() {
		return IsMove;
	}

	public void setIsMove(String isMove) {
		IsMove = isMove;
	}

	public String getParamOID() {
		return ParamOID;
	}

	public void setParamOID(String paramOID) {
		ParamOID = paramOID;
	}

	public String getParamDocNo() {
		return ParamDocNo;
	}

	public void setParamDocNo(String paramDocNo) {
		ParamDocNo = paramDocNo;
	}
	
	public String getSerialNo() {
		return SerialNo;
	}

	public void setSerialNo(String serialNo) {
		SerialNo = serialNo;
	}

	public String getLotNo() {
		return LotNo;
	}

	public void setLotNo(String lotNo) {
		LotNo = lotNo;
	}
	
	public String getRefOID() {
		return RefOID;
	}

	public void setRefOID(String refOID) {
		RefOID = refOID;
	}

	public String getIsItemPromotionGiveaways() {
		return IsItemPromotionGiveaways;
	}

	public void setIsItemPromotionGiveaways(String isItemPromotionGiveaways) {
		IsItemPromotionGiveaways = isItemPromotionGiveaways;
	}

	public String getIsItemPromotionSets() {
		return IsItemPromotionSets;
	}

	public void setIsItemPromotionSets(String isItemPromotionSets) {
		IsItemPromotionSets = isItemPromotionSets;
	}

	public ResultSet selectPOS() throws Exception {
        String StrSql = "SELECT " +
		        			"[OID]," +
							"[LastModified]," +
							"[ModifiedBy]," +
							"[CreatedDate]," +
							"[CreatedBy]," +	
							"[IsActive]," +
							"[IsDeleted]," +
							
							"[DocNo]," +
							"[ArOID]," +
							"[ArCode]," +
							"[ArName]," +
							"[UserOID]," +
							
							"[UserName]," +
							"[DocDateTime]," +
							"[DocDate]," +
							"[CompanyOID]," +
							"[CompanyName]," +
							
							"[CompanyCode]," +
							"[SaleType]," +
							"[TotalAmount]," +
							"[DiscountAmount]," +
							"[ReceiveMoney]," +
							
							"[NetTotalAmount]," +
							"[DocumentStatus]," +
							"[BalanceStatus]," +
							"[ArType]," +
							"[RefDocNo]," +
							
							"[PayableDateTime]," +
							"[PayableDate]," +
							"[CountDetail] " +
          
                  "FROM 	[dbo].[udfCarCare_ServicePOS]() " ;
                
		StrSql += "WHERE 	[IsActive] = '1' " +
				  "AND		[IsDeleted] = '0' ";

		if(getParamOID() != null)
			StrSql += "AND	[OID] = '" + getParamOID() + "' ";
		
		if(getParamDocNo() != null)
			StrSql += "AND	[DocNo] LIKE '%" + getParamDocNo() + "%' ";
		
		if(getParamDocS() != null)
			StrSql += "AND	[DocumentStatus] = '" + getParamDocS() + "' ";
		
		if(getParamAr() != null && !getParamAr().equals(""))
			StrSql += "AND	([ArCode] LIKE '%" + getParamAr() + "%' OR [ArName] LIKE '%" + getParamAr() + "%')";
	
		
		if(getParamSDate() != null && getParamSDate().length() == 10 && getParamEDate().length() == 10){
			StrSql += "AND ((CAST(FLOOR(CAST([DocDateTime] AS FLOAT)) AS DATETIME)  >= '"+DateTime.convertDate(getParamSDate())+"') " +"AND  (CAST(FLOOR(CAST([DocDateTime] AS FLOAT)) AS DATETIME)  <= '"+DateTime.convertDate(getParamEDate())+"')) " ;
		}else if(getParamSDate() != null && getParamSDate().length() == 10){
			StrSql += "AND (CAST(FLOOR(CAST([DocDateTime] AS FLOAT)) AS DATETIME) = '"+DateTime.convertDate(getParamSDate())+"') ";
		}else if(getParamSDate() != null && getParamEDate().length() == 10){
			StrSql += "AND (CAST(FLOOR(CAST([DocDateTime] AS FLOAT)) AS DATETIME) = '"+DateTime.convertDate(getParamEDate())+"') ";
		}

		StrSql += "ORDER BY [OID] DESC ";
		//System.out.println(StrSql);
		
		return con.selectData(StrSql);
    }
	
	public ResultSet selectPOSLists() throws Exception {
        String StrSql = "SELECT " +
			        		"[OID]," +
							"[LastModified]," +
							"[ModifiedBy]," +
							"[CreatedDate]," +
							"[CreatedBy]," +	
							"[IsActive]," +
							"[IsDeleted]," +
							
							"[POSOID]," +
							"[ItemOID]," +
							"[ItemCode]," +
							"[ItemName]," +
							"[ItemSizeOID]," +
							"[ItemSizeName]," +
							"[BrandOID]," +
							"[BrandName]," +
							"[ModelOID]," +
							"[ModelName]," +
							"[Qty]," +
							"[Price]," +
							"[TotalAmount]," +
							"[UnitOID]," +
							"[ItemUnitName]," +
							"[WHOID]," +
							"[Name]," +
							"[ICZoneOID]," +
							"[ICZoneName]," +
							"[ICStorageOID]," +
							"[ICStorageName]," +
							"[ICShelfOID]," +
							"[ICShelfName]," +
							"[ICColumnOID]," +
							"[ICColumnName]," +
							"[StkInOutDateTime]," +
							"[StkInOutDate]," +
							"[Status]," +
							"[IsMove]," +
							"[Discount]," +
							"[NetAmount]," +
							"[ItemPicPath] " +
//							"[SerialNo]," +
//							"[LotNo]," +
//							"[IsItemPromotionSpecialSalePrices]," +
//							"[IsItemPromotionQuantitySalePrices]," +
//							"[IsItemPromotionGiveaways]," +
//							"[IsItemPromotionSets] " +
          
                  "FROM 	[dbo].[udfCarCare_SerVicePOSLists]() " ;
                
		StrSql += "WHERE 	[IsActive] = '1' " +
				  "AND		[IsDeleted] = '0' ";

		if(getParamOID() != null)
			StrSql += "AND	[OID] = '" + getParamOID() + "' ";

		if(getParamPOSOID() != null)
			StrSql += "AND	[POSOID] = '" + getParamPOSOID() + "' ";
		

		//System.out.println(StrSql);
		
		return con.selectData(StrSql);
    }
	
	public ResultSet selectPOSListGroupBy() throws Exception {
        String StrSql = "SELECT " +
							"[POSOID]," +
							"[ItemOID]," +
							"[ItemCode]," +
							"[ItemName]," +
							"SUM([Qty]) AS [Qty]," +
							"[Price]," +
							"SUM([TotalAmount]) AS [TotalAmount]," +
							"SUM([Discount]) AS [Discount]," +
							"SUM([NetAmount]) AS [NetAmount]," +
							"[UnitOID]," +
							"[ItemUnitName]," +
							"[ItemPicPath]," +
							"[IsItemPromotionSpecialSalePrices]," +
							"[IsItemPromotionQuantitySalePrices]," +
							"[IsItemPromotionGiveaways]," +
							"[IsItemPromotionSets] " +
          
                  "FROM 	[dbo].[udfCarCare_SerVicePOSLists]() " ;
                
		StrSql += "WHERE 	[IsActive] = '1' " +
				  "AND		[IsDeleted] = '0' ";

		if(getParamPOSOID() != null)
			StrSql += "AND	[POSOID] = '" + getParamPOSOID() + "' ";
		
		StrSql += "GROUP BY	 [POSOID]," +
							"[ItemOID]," +
							"[ItemCode]," +
							"[ItemName]," +
							"[Price]," +
							"[UnitOID]," +
							"[ItemUnitName]," +
							"[ItemPicPath]," +
							"[IsItemPromotionSpecialSalePrices]," +
							"[IsItemPromotionQuantitySalePrices]," +
							"[IsItemPromotionGiveaways]," +
							"[IsItemPromotionSets] " ;
		
		//System.out.println(StrSql);
		
		return con.selectData(StrSql);
    }
	
	public ResultSet selectSales() throws Exception {
        String StrSql = "SELECT " +
        					"[ItemOID]," +
							"[ItemCode]," +
							"[ItemName]," +
							"SUM([Qty]) AS [QtySales]," +
							"SUM([NetAmount]) AS [NetAmount]," +
							"(SELECT SUM([ICStkWarehouse].[Qty]) FROM [dbo].[ICStkWarehouse] WHERE [ICStkWarehouse].[ItemOID] = [POSLists].[ItemOID]) AS [QtyInventory] " +
						
                  "FROM 	[dbo].[udfCarCare_SerVicePOSLists]() AS [POSLists] " ;
                
		StrSql += "WHERE 	[IsActive] = '1' " +
				  "AND		[IsDeleted] = '0' " +
				  "AND		[DocumentStatus] = 1 ";

		if(getParamSDate() != null && getParamSDate().length() == 10 && getParamEDate().length() == 10){
			StrSql += "AND ((CAST(FLOOR(CAST([DocDateTime] AS FLOAT)) AS DATETIME)  >= '"+DateTime.convertDate(getParamSDate())+"') " +"AND  (CAST(FLOOR(CAST([DocDateTime] AS FLOAT)) AS DATETIME)  <= '"+DateTime.convertDate(getParamEDate())+"')) " ;
		}else if(getParamSDate() != null && getParamSDate().length() == 10){
			StrSql += "AND (CAST(FLOOR(CAST([DocDateTime] AS FLOAT)) AS DATETIME) = '"+DateTime.convertDate(getParamSDate())+"') ";
		}else if(getParamSDate() != null && getParamEDate().length() == 10){
			StrSql += "AND (CAST(FLOOR(CAST([DocDateTime] AS FLOAT)) AS DATETIME) = '"+DateTime.convertDate(getParamEDate())+"') ";
		}
		
		StrSql += "GROUP BY  [ItemOID]," +
							"[ItemCode]," +
							"[ItemName] " ;
		
		//System.out.println(StrSql);
		
		return con.selectData(StrSql);
    }
	

	public String stpPOSManagement(String OperationType) throws Exception {
		conn = con.Connect();
        java.sql.CallableStatement cstmt = conn.prepareCall("{call stpCarCare_ServicePOSManagement"
                + "("
                + "?,?,?,?,?,"
                + "?,?,?,?,?,"
                + "?,?,?,?,?,"
                + "?,?,?,?,?,"
                + "?"
                + ")}");

        try {
            if (conn != null) {
                cstmt.setString(1, OperationType);
                cstmt.setString(2, getPOSOID());
                cstmt.setString(3, getUsrOpt());
                cstmt.setString(4, getIsActive());
                cstmt.setString(5, getIsDeleted());

                cstmt.setString(6, getDocNo());
                cstmt.setString(7, getArOID());
                cstmt.setString(8, getUserOID());
                cstmt.setString(9, getDocDateTime());
        		cstmt.setString(10, getCompanyOID());
        		
        		cstmt.setString(11, getSaleType());
        		cstmt.setDouble(12, getTotalAmount());
        		cstmt.setDouble(13, getDiscountAmount());
        		cstmt.setDouble(14, getReceiveMoney());
        		cstmt.setDouble(15, getNetTotalAmount());
        		
        		cstmt.setString(16, getDocumentStatus());
        		cstmt.setString(17, getStatus());
        		cstmt.setString(18, getArType());
        		cstmt.setString(19, getRefDocNo());
			    cstmt.setString(20, getPayableDateTime());
			    
                cstmt.registerOutParameter(21, Types.VARCHAR);
                cstmt.execute();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return cstmt.getString(21);
    }
	
	public String stpPOSListsManagement(String OperationType) throws Exception {
		conn = con.Connect();
        java.sql.CallableStatement cstmt = conn.prepareCall("{call stpCarCare_ServicePOSListsManagement"
                + "("
                + "?,?,?,?,?,"
                + "?,?,?,?,?,"
                + "?,?,?,?,?,"
                + "?,?,?,?,?,"
                + "?,?,?,?,?," +
                  "?)}");
        
        /*
        System.out.println(OperationType);
        System.out.println(getPOSListsOID());
        System.out.println(getQty());
        System.out.println(getPrice());
        System.out.println(getTotalAmount());
        System.out.println(getDiscountAmount());
        */
        
        try {
            if (conn != null) {
                cstmt.setString(1, OperationType);
                cstmt.setString(2, getPOSListsOID());
                cstmt.setString(3, getUsrOpt());
                cstmt.setString(4, getIsActive());
                cstmt.setString(5, getIsDeleted());

                cstmt.setString(6, getPOSOID());
                cstmt.setString(7, getItemOID());
                cstmt.setInt(8, getQty());
                cstmt.setDouble(9, getPrice());
                cstmt.setDouble(10, getTotalAmount());
                
                cstmt.setString(11, getUnitOID());
                cstmt.setString(12, getWHOID());
                cstmt.setString(13, getICZoneOID());
                cstmt.setString(14, getICStorageOID());
                cstmt.setString(15, getICShelfOID());
                     
                cstmt.setString(16, getICColumnOID());
                cstmt.setString(17, getStkInOutDateTime());
                cstmt.setString(18, getStatus());
                cstmt.setString(19, getIsMove());
                cstmt.setDouble(20, getDiscountAmount());
                
                cstmt.setString(21, "");
                cstmt.setString(22, getLotNo());
                cstmt.setString(23, getRefOID());
                cstmt.setString(24, getIsItemPromotionGiveaways());
                cstmt.setString(25, getIsItemPromotionSets());
						
                cstmt.registerOutParameter(26, Types.VARCHAR);
                
                cstmt.execute();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return cstmt.getString(26);
    }

    public void closeConnecttion() throws Exception {
    	 if (conn != null) {
             conn.close();
         }
    }

    public void closeConn() throws Exception {
        conn.close();
    }	
    
    public long DEFINE_ServicePOS(String UserGroup) throws Exception{
		rs = null;
		myDb = new SQLiteDBClass(getContext());
		db = myDb.getWritableDatabase();
		
		try {
			setParamDocNo(UserGroup);
			rs = selectPOS();
			while (rs.next()) {
//				try{
//					long check = UpdateServicePOSstatusUpdate(
//								 rs.getString("OID"), 
//								 rs.getString("DocNo"), 
//								 "0", 
//								 "0");
//					if(check<0){
//						return -7;
//					}
//				}catch(Exception e){
//					
//				}
				try{
					
//					if(UpdateServicePOSstatusUpdate(
//							rs.getString("OID"), 
//							 rs.getString("DocNo"), 
//							 "1", 
//							 "0") >0){
//						
//					}
//					try{
//						UpdateServicePOSstatusUpdate(
//								rs.getString("OID"), 
//								 rs.getString("DocNo"), 
//								"0", 
//								"0");
//					}catch(Exception ee){
//						
//					}
					
					ContentValues Val = new ContentValues();
					Val.put("ServicePOSOID", rs.getString("OID"));
					
					Val.put("DocNo", rs.getString("DocNo"));
					Val.put("RefDocNo", rs.getString("RefDocNo"));
					Val.put("ArOID", rs.getString("ArOID"));
					Val.put("UserOID", rs.getString("UserOID"));
					String time = rs.getString("DocDateTime").substring(10, 16); 
					Val.put("DocDateTime",time);
				//	
					String timePay = rs.getString("PayableDateTime").substring(10, 16); 
					Val.put("PayableDateTime",timePay);
					Val.put("CompanyOID", rs.getString("CompanyOID"));
					Val.put("SaleType", rs.getString("SaleType"));
					Val.put("ArType", rs.getString("ArType"));
					Val.put("TotalAmount", Number.addComma(Double.valueOf(rs.getString("TotalAmount")), 2));
					
					Val.put("DiscountAmount", Number.addComma(Double.valueOf(rs.getString("DiscountAmount")), 2));
					Val.put("ReceiveMoney", Number.addComma(Double.valueOf(rs.getString("ReceiveMoney")), 2));
					Val.put("NetTotalAmount", Number.addComma(Double.valueOf(rs.getString("NetTotalAmount")), 2));
					Val.put("DocumentStatus", rs.getString("DocumentStatus"));
					Val.put("BalanceStatus", rs.getString("BalanceStatus"));
				//
					Val.put("LastUpdate", rs.getString("LastModified"));
					Val.put("StatusUpdate", "1");				
					Val.put("StatusDoc", rs.getString("IsDeleted"));
					db.insert(TABLE_ServicePOS, null, Val);
					
				}catch(Exception e){
					try{
						String time = rs.getString("DocDateTime").substring(10, 16); 
						String timePay = rs.getString("PayableDateTime").substring(10, 16); 
						UpdateServicePOSFromServer( 
								rs.getString("DocNo"), 
								rs.getString("RefDocNo"), 
								rs.getString("ArOID"), 
								rs.getString("UserOID"),
								time, 
								
								timePay, 
								rs.getString("CompanyOID"), 
								rs.getString("SaleType"), 
								rs.getString("ArType"), 
								Number.addComma(Double.valueOf(rs.getString("TotalAmount")), 2), 
								
								Number.addComma(Double.valueOf(rs.getString("DiscountAmount")), 2), 
								Number.addComma(Double.valueOf(rs.getString("ReceiveMoney")), 2),
								Number.addComma(Double.valueOf(rs.getString("NetTotalAmount")), 2),
								rs.getString("DocumentStatus"), 
								rs.getString("BalanceStatus"), 
								
								rs.getString("CreatedBy"), 
								rs.getString("CreatedDate"), 
								rs.getString("LastModified"), 
								"1", 
								rs.getString("IsDeleted"));
					}catch(Exception e2){
						return -5;
					}
				}
			}
		} catch (Exception e) {
//			Log.d("TABLE_ServicePOS",
//					"Create Table TABLE_ServicePOS not Successfully.");
			return  -2;
		}
		
		db.close();
		return 0;
	}
    
//	try{
//		if(!SelectAll_ServicePOS("", rs.getString("DocNo"), "").equals("")){
//			String time = rs.getString("DocDateTime").substring(10, 16); 
//			String timePay = rs.getString("PayableDateTime").substring(10, 16); 
//			try{
//				UpdateServicePOSFromServer( 
//						rs.getString("DocNo"), 
//						rs.getString("RefDocNo"), 
//						rs.getString("ArOID"), 
//						rs.getString("UserOID"),
//						time, 
//						
//						timePay, 
//						rs.getString("CompanyOID"), 
//						rs.getString("SaleType"), 
//						rs.getString("ArType"), 
//						rs.getString("TotalAmount"), 
//						
//						rs.getString("DiscountAmount"), 
//						rs.getString("ReceiveMoney"), 
//						rs.getString("NetTotalAmount"), 
//						rs.getString("DocumentStatus"), 
//						rs.getString("BalanceStatus"), 
//						
//						"", 
//						"", 
//						"", 
//						"1", 
//						rs.getString("IsDeleted"));
//			}catch(Exception e){
//				return -5;
//			}
//			
////			return 111;
//		}else{
//			return 1111;
//		}
//	
//}catch(Exception e){
//	ContentValues Val = new ContentValues();
//	Val.put("ServicePOSOID", rs.getString("OID"));
//
//	Val.put("DocNo", rs.getString("DocNo"));
//	Val.put("RefDocNo", rs.getString("RefDocNo"));
//	Val.put("ArOID", rs.getString("ArOID"));
//	Val.put("UserOID", rs.getString("UserOID"));
//	String time = rs.getString("DocDateTime").substring(10, 16); 
//	Val.put("DocDateTime",time);
////	
//	String timePay = rs.getString("PayableDateTime").substring(10, 16); 
//	Val.put("PayableDateTime",timePay);
//	Val.put("CompanyOID", rs.getString("CompanyOID"));
//	Val.put("SaleType", rs.getString("SaleType"));
//	Val.put("ArType", rs.getString("ArType"));
//	Val.put("TotalAmount", rs.getString("TotalAmount"));
//	
//	Val.put("DiscountAmount", rs.getString("DiscountAmount"));
//	Val.put("ReceiveMoney", rs.getString("ReceiveMoney"));
//	Val.put("NetTotalAmount", rs.getString("NetTotalAmount"));
//	Val.put("DocumentStatus", rs.getString("DocumentStatus"));
//	Val.put("BalanceStatus", rs.getString("BalanceStatus"));
////
//	Val.put("UserModify", rs.getString("CreatedBy"));
//	Val.put("CreateTime", rs.getString("CreatedDate"));
//	Val.put("LastUpdate", rs.getString("LastModified"));
//	Val.put("StatusUpdate", "1");				
//	Val.put("StatusDoc", rs.getString("IsDeleted"));
//	db.insert(TABLE_ServicePOS, null, Val);
//}
    
    
    public String[][] SelectAll_ServicePOS(String StatusDoc,String Docno,String StatusUpdate) throws Exception{
		try {
			String arrData[][] = null;
			
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();
			
			String strSQL = "SELECT  ServicePOSOID As _id , * FROM "
					+ TABLE_ServicePOS ;
			strSQL += " WHERE [DocNo] LIKE '%" + Docno + "%' ";
			
			if(!StatusDoc.equals("")){
				strSQL += " AND [StatusDoc] LIKE '" + StatusDoc + "' ";
			}
			if (!StatusUpdate.equals("")) {
				strSQL += " AND [StatusUpdate] LIKE '" + StatusUpdate + "' ";
			}
			strSQL += " ORDER BY [DocNo] ASC ";
			Cursor cursor = db.rawQuery(strSQL, null);
			
			if (cursor != null) {
				if (cursor.moveToFirst()) {
					arrData = new String[cursor.getCount()][cursor
							.getColumnCount()];
					int i = 0;
					do {
						arrData[i][0] = cursor.getString(1);

						arrData[i][1] = cursor.getString(2);
						arrData[i][2] = cursor.getString(3);
						arrData[i][3] = cursor.getString(4);
						arrData[i][4] = cursor.getString(5);
						arrData[i][5] = cursor.getString(6);

						arrData[i][6] = cursor.getString(7);
						arrData[i][7] = cursor.getString(8);
						arrData[i][8] = cursor.getString(9);
						arrData[i][9] = cursor.getString(10);
						arrData[i][10] = cursor.getString(11);

						arrData[i][11] = cursor.getString(12);
						arrData[i][12] = cursor.getString(13);
						arrData[i][13] = cursor.getString(14);
						arrData[i][14] = cursor.getString(15);
						arrData[i][15] = cursor.getString(16);

						arrData[i][16] = cursor.getString(17);
						arrData[i][17] = cursor.getString(18);
						arrData[i][18] = cursor.getString(19);
						arrData[i][19] = cursor.getString(20);
						arrData[i][20] = cursor.getString(21);

						i++;
					} while (cursor.moveToNext());
				}
			}
			cursor.close();

			return arrData;

		} catch (Exception e) {
			return null;
		}
	}
    
    public long InsertServicePOSOID(String 
    				ServicePOSOID,

    				String DocNo,
    				String RefDocNo, 
    				String ArOID, 
    				String UserOID,
    				String DocDateTime,

    				String PayableDateTime,
    				String CompanyOID, 
    				String SaleType,
    				String ArType, 
    				String TotalAmount,

    				String DiscountAmount,
    				String ReceiveMoney, 
    				String NetTotalAmount,
    				String DocumentStatus, 
    				String BalanceStatus,

    				String UserModify, 
    				String CreateTime,
    				String LastUpdate,
    				String StatusUpdate,
    				String StatusDoc) {
    			// TODO Auto-generated method stub

    			try {
    				myDb = new SQLiteDBClass(getContext());
    				db = myDb.getWritableDatabase();

    				ContentValues Val = new ContentValues();
    				Val.put("ServicePOSOID", ServicePOSOID);

    				Val.put("DocNo", DocNo);
    				Val.put("RefDocNo", RefDocNo);
    				Val.put("ArOID", ArOID);
    				Val.put("UserOID", UserOID);
    				Val.put("DocDateTime", DocDateTime);

    				Val.put("PayableDateTime", PayableDateTime);
    				Val.put("CompanyOID", CompanyOID);
    				Val.put("SaleType", SaleType);
    				Val.put("ArType", ArType);
    				Val.put("TotalAmount", TotalAmount);

    				Val.put("DiscountAmount", DiscountAmount);
    				Val.put("ReceiveMoney", ReceiveMoney);
    				Val.put("NetTotalAmount", NetTotalAmount);
    				Val.put("DocumentStatus", DocumentStatus);
    				Val.put("BalanceStatus", BalanceStatus);

    				Val.put("UserModify", UserModify);
    				Val.put("CreateTime", CreateTime);
    				Val.put("LastUpdate", LastUpdate);
    				Val.put("StatusUpdate", StatusUpdate);
    				Val.put("StatusDoc", StatusDoc);

    				long rows = db.insert(TABLE_ServicePOS, null, Val);

    				db.close();
    				return rows; // return rows inserted.

    			} catch (Exception e) {
    				return -1;
    			}

    		}
	public long UpdateServicePOS(
			String DocNo,
			String RefDocNo, 
			
			String PayableDateTime,

			String UserModify, 
			String LastUpdate,
			String StatusUpdate
		) {
		// TODO Auto-generated method stubdsa

		try {
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			ContentValues Val = new ContentValues();
			
			Val.put("RefDocNo", RefDocNo);
			
			Val.put("PayableDateTime", PayableDateTime);
		
			Val.put("UserModify", UserModify);
			Val.put("LastUpdate", LastUpdate);
			Val.put("StatusUpdate", StatusUpdate);
			
//			long rows = db.insert(TABLE_ServicePOSLists, null, Val);	
			long rows = db.update(TABLE_ServicePOS, Val, " DocNo = ?",
					new String[] { String.valueOf(DocNo) });
			db.close();
			return rows; // return rows inserted.

		} catch (Exception e) {
			return -1;
		}

	}
	
	public long UpdateServicePOSFromServer(
			String DocNo,
			String RefDocNo, 
			String ArOID, 
			String UserOID,
			String DocDateTime,
			
			String PayableDateTime,
			String CompanyOID, 
			String SaleType,
			String ArType, 
			String TotalAmount,

			String DiscountAmount,
			String ReceiveMoney, 
			String NetTotalAmount,
			String DocumentStatus, 
			String BalanceStatus,

			String UserModify, 
			String CreateTime,
			String LastUpdate,
			String StatusUpdate,
			String StatusDoc
		) {
		// TODO Auto-generated method stubdsa

		try {
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			ContentValues Val = new ContentValues();
			
			Val.put("RefDocNo", RefDocNo);
			Val.put("ArOID", ArOID);
			Val.put("UserOID", UserOID);
			Val.put("DocDateTime", DocDateTime);

			Val.put("PayableDateTime", PayableDateTime);
			Val.put("CompanyOID", CompanyOID);
			Val.put("SaleType", SaleType);
			Val.put("ArType", ArType);
			Val.put("TotalAmount", TotalAmount);

			Val.put("DiscountAmount", DiscountAmount);
			Val.put("ReceiveMoney", ReceiveMoney);
			Val.put("NetTotalAmount", NetTotalAmount);
			Val.put("DocumentStatus", DocumentStatus);
			Val.put("BalanceStatus", BalanceStatus);
//
//			Val.put("UserModify", UserModify);
//			Val.put("CreateTime", CreateTime);
//			Val.put("LastUpdate", LastUpdate);
			Val.put("StatusUpdate", StatusUpdate);
			Val.put("StatusDoc", StatusDoc);
//			long rows = db.insert(TABLE_ServicePOSLists, null, Val);	
			long rows = db.update(TABLE_ServicePOS, Val, " DocNo = ?",
					new String[] { String.valueOf(DocNo) });
			db.close();
			return rows; // return rows inserted.

		} catch (Exception e) {
			return -1;
		}

	}
	
	public long UpdateServicePOSStatuschancg(
			String ServicePOSOID,
			
			String DocNo,
			
			String SaleType, 

			String LastUpdate,
			String StatusUpdate,
			String StatusDoc
		) {
		// TODO Auto-generated method stubdsa

		try {
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			ContentValues Val = new ContentValues();
			Val.put("ServicePOSOID", ServicePOSOID);
			Val.put("DocNo", DocNo);
			
			Val.put("SaleType", SaleType);
		
			Val.put("LastUpdate", LastUpdate);
			Val.put("StatusUpdate", StatusUpdate);
			Val.put("StatusDoc", StatusDoc);
			
//			long rows = db.insert(TABLE_ServicePOSLists, null, Val);	
			long rows = db.update(TABLE_ServicePOS, Val, " ServicePOSOID = ?",
					new String[] { String.valueOf(ServicePOSOID) });
			db.close();
			return rows; // return rows inserted.

		} catch (Exception e) {
			return -1;
		}

	}
	
	public long UpdatePriceAndDuration(
			String DocNo,
			
			String ArType,
			
			String TotalAmount, 
			String DiscountAmount, 
			String ReceiveMoney, 
			String NetTotalAmount, 
			
			String StatusUpdate
		) {
		// TODO Auto-generated method stubdsa

		try {
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			ContentValues Val = new ContentValues();
			Val.put("DocNo", DocNo);
			
			Val.put("ArType", ArType);
			
			Val.put("TotalAmount", TotalAmount);
			Val.put("DiscountAmount", DiscountAmount);
			Val.put("ReceiveMoney", ReceiveMoney);
			Val.put("NetTotalAmount", NetTotalAmount);
		
			Val.put("StatusUpdate", StatusUpdate);
			
//			long rows = db.insert(TABLE_ServicePOSLists, null, Val);	
			long rows = db.update(TABLE_ServicePOS, Val, " DocNo = ?",
					new String[] { String.valueOf(DocNo) });
			db.close();
			return rows; // return rows inserted.

		} catch (Exception e) {
			return -1;
		}

	}
	public long UpdateServicePOSstatusUpdate(
			String ServicePOSOID,
			String DocNo,
			
			String StatusUpdate,
			String StatusDoc
		) {
		// TODO Auto-generated method stubdsa

		try {

			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();
			
			ContentValues Val = new ContentValues();
			Val.put("ServicePOSOID", ServicePOSOID);

			Val.put("DocNo", DocNo);
			Val.put("StatusUpdate", StatusUpdate);
			Val.put("StatusDoc", StatusDoc);
//			long rows = db.insert(TABLE_ServicePOSLists, null, Val);	
			long rows = db.update(TABLE_ServicePOS, Val, " DocNo = ?",
					new String[] { String.valueOf(DocNo) });
			db.close();
			return rows; // return rows inserted.

		} catch (Exception e) {
			return -1;
		}

	}
	
	public long UpdateServicePOSstatusUpdateByDoc(
			String DocNo,
			
			String StatusUpdate,
			String StatusDoc
		) {
		// TODO Auto-generated method stubdsa

		try {
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			ContentValues Val = new ContentValues();
			Val.put("DocNo", DocNo);

			Val.put("StatusUpdate", StatusUpdate);
			Val.put("StatusDoc", StatusDoc);
//			long rows = db.insert(TABLE_ServicePOSLists, null, Val);	
			long rows = db.update(TABLE_ServicePOS, Val, " DocNo = ?",
					new String[] { String.valueOf(DocNo) });
			db.close();
			return rows; // return rows inserted.

		} catch (Exception e) {
			return -1;
		}
	}
	
	  public long UpdatetoServer_POS() throws Exception{
		  	ServicePOS pos = new ServicePOS();
	    	String data[][];
	    	Boolean insert = false;
	    	int length = 0;
	    	rs = null;
	    	try{
	    		try{
	    			data = SelectAll_ServicePOS("", "","0");
	    		}catch(Exception e){
	    			data=null;
	    			return +88;
	    		}finally{
	    			db.close();
	    		}
	    		
	    		length = data.length;
	    		for(int i=0;i<length;i++){
	    				
	    				pos.setParamDocNo(data[i][1]);
	    				rs = pos.selectPOS();
	    				if(rs.next()){
	    					insert=false;
	    				}else{
	    					insert=true;
	    				}
	    				
	    				pos.setPOSOID(data[i][0]);
	    				pos.setUsrOpt(data[i][16]);
	    				pos.setIsActive("1");
	    				pos.setIsDeleted(data[i][20]);
	    				
	    				pos.setDocNo(data[i][1]);
	    				pos.setDocDateTime(data[i][5]);
	    				pos.setPayableDateTime(data[i][6]);
	    				
	    				pos.setSaleType(data[i][8]);
	    				pos.setArType(data[i][9]);
	    				pos.setTotalAmount(Number.unCommaReturnDouble(data[i][10]));
	    				pos.setDiscountAmount(Number.unCommaReturnDouble(data[i][11]));
	    				pos.setReceiveMoney(Number.unCommaReturnDouble(data[i][12]));
	    				pos.setNetTotalAmount(Number.unCommaReturnDouble(data[i][13]));
	    				pos.setArOID(data[i][3]);
	    				pos.setUserOID(data[i][4]);
	    				pos. setCompanyOID(data[i][7]);
	    				pos.setRefDocNo(data[i][2]);
	    			    if(insert == true){
	    			    	try {
	        					if(pos.stpPOSManagement("Insert") != null){
	        						long check = UpdateServicePOSstatusUpdate
	    									(	data[i][0], 
	    										data[i][1],
	    										"1",
	    										data[i][20]
	    									);
	    	        						
	    	        						if(check<0){
	    	        							return -9;
	    	        						}
	        					}
	        					
	        				} catch (Exception e) {
	        					 return -2;
	        				}
	    			    }else{
	    			    	try {
	        					if(pos.stpPOSManagement("Update") != null){
	        						long check = UpdateServicePOSstatusUpdate
									(	data[i][0], 
										data[i][1],
										"1",
										data[i][20]
									);
	        						if(data[i][20].equals("1")){
	        							pos.stpPOSManagement("Delete");
	        						}
	        						if(check<0){
	        							return -3;
	        						}
	        					}
	        				} catch (Exception e) {
	        					 return -4;
	        				}
	    			    }
	    		}
	    	}catch(Exception e){
	             return -5;
	    	}finally{
	    		rs.close();
	    	}
			return 0;
	    }

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}
	

	public void DEFINE_ServicePOSLists() throws Exception {
		rs = null;
		
		myDb = new SQLiteDBClass(getContext());
		db = myDb.getWritableDatabase();

		try {
			rs = selectPOSLists();
			while (rs.next()) {
				ContentValues Val = new ContentValues();
				Val.put("ServicePOSListsOID", rs.getString("OID"));

				Val.put("POSOID", rs.getString("POSOID"));
				Val.put("ItemOID", rs.getString("ItemOID"));
				Val.put("Qty", rs.getString("Qty"));
				Val.put("Price", rs.getString("Price"));
				Val.put("TotalAmount", rs.getString("TotalAmount"));

				Val.put("Discount", rs.getString("Discount"));
				Val.put("NetAmount", rs.getString("NetAmount"));
				Val.put("UnitOID", rs.getString("UnitOID"));
				Val.put("WHOID", rs.getString("WHOID"));
				Val.put("ICZoneOID", rs.getString("ICZoneOID"));
				
				Val.put("ICStorageOID", rs.getString("ICStorageOID"));
				Val.put("ICShelfOID", rs.getString("ICShelfOID"));
				Val.put("ICColumnOID", rs.getString("ICColumnOID"));
				Val.put("StkInOutDateTime", rs.getString("StkInOutDateTime"));
				Val.put("Status", rs.getString("Status"));
				
				//
				Val.put("UserModify", rs.getString("CreatedBy"));
				// Val.put("CreateTime", rs.getString("CreateTime"));
				// Val.put("LastUpdate", rs.getString("LastUpdate"));
				Val.put("StatusUpdate", "1");
				// Val.put("StatusDoc", rs.getString("StatusDoc"));

				db.insert(TABLE_ServicePOSLists, null, Val);
			}
		} catch (Exception e) {
			Log.d("TABLE_SerVicePOSLists",
					"Create Table TABLE_SerVicePOSLists not Successfully.");
		}finally{
			try {
				closeConnecttion();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		Log.d("TABLE_SerVicePOSLists", "Create Table TABLE_SerVicePOSLists Successfully.");
		db.close();
	}
	
	public String[][] SelectAll_ServicePOSList(String POSDocOID,String DocStatus,String StatusUpdate) {
		try {
			String arrData[][] = null;
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();
			String strSQL = "SELECT  ServicePOSListsOID As _id , * FROM "
					+ TABLE_ServicePOSLists;
			strSQL += " WHERE [POSOID] LIKE '%" + POSDocOID + "%' ";
//			if (!POSDocOID.equals("")) {
//				strSQL += " WHERE [POSOID] LIKE '%" + POSDocOID + "%' ";
//			}
			if (!DocStatus.equals("")) {
				strSQL += " AND [StatusDoc] LIKE '" + DocStatus + "' ";
			}
			if (!StatusUpdate.equals("")) {
				strSQL += " AND [StatusUpdate] LIKE '" + StatusUpdate + "' ";
			}
			Cursor cursor = db.rawQuery(strSQL, null);
			if (cursor != null) {
				if (cursor.moveToFirst()) {
					arrData = new String[cursor.getCount()][cursor
							.getColumnCount()];
					int i = 0;
					do {
						arrData[i][0] = cursor.getString(1);

						arrData[i][1] = cursor.getString(2);
						arrData[i][2] = cursor.getString(3);
						arrData[i][3] = cursor.getString(4);
						arrData[i][4] = cursor.getString(5);
						arrData[i][5] = cursor.getString(6);

						arrData[i][6] = cursor.getString(7);
						arrData[i][7] = cursor.getString(8);
						arrData[i][8] = cursor.getString(9);
						arrData[i][9] = cursor.getString(10);
						arrData[i][10] = cursor.getString(11);

						arrData[i][11] = cursor.getString(12);
						arrData[i][12] = cursor.getString(13);
						arrData[i][13] = cursor.getString(14);
						arrData[i][14] = cursor.getString(15);
						arrData[i][15] = cursor.getString(16);

						arrData[i][16] = cursor.getString(17);
						arrData[i][17] = cursor.getString(18);
						arrData[i][18] = cursor.getString(19);
						arrData[i][19] = cursor.getString(20);
						arrData[i][20] = cursor.getString(21);

						i++;
					} while (cursor.moveToNext());
				}
			}
			cursor.close();

			return arrData;

		} catch (Exception e) {
			return null;
		}
	}
	
	public long InsertServicePOSLists(
			String ServicePOSListsOID,
			
			String POSOID, 
			String ItemOID, 
			String Qty, 
			String Price,
			String TotalAmount,
			
			String Discount, 
			String NetAmount, 
			String UnitOID, 
			String WHOID,
			String ICZoneOID,
			
			String ICStorageOID, 
			String ICShelfOID, 
			String ICColumnOID, 
			String StkInOutDateTime,
			String Status,
			
			String UserModify, 
			String CreateTime,
			String LastUpdate, 
			String StatusUpdate,
			String StatusDoc) {
		// TODO Auto-generated method stub

		try {
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			ContentValues Val = new ContentValues();
			Val.put("ServicePOSListsOID", ServicePOSListsOID);

			Val.put("POSOID", POSOID);
			Val.put("ItemOID", ItemOID);
			Val.put("Qty", Qty);
			Val.put("Price", Price);
			Val.put("TotalAmount", TotalAmount);
			
			Val.put("Discount", Discount);
			Val.put("NetAmount", NetAmount);
			Val.put("UnitOID", UnitOID);
			Val.put("WHOID", WHOID);
			Val.put("ICZoneOID", ICZoneOID);
			
			Val.put("ICStorageOID", ICStorageOID);
			Val.put("ICShelfOID", ICShelfOID);
			Val.put("ICColumnOID", ICColumnOID);
			Val.put("StkInOutDateTime", StkInOutDateTime);
			Val.put("Status", Status);

			Val.put("UserModify", UserModify);
			Val.put("CreateTime", CreateTime);
			Val.put("LastUpdate", LastUpdate);
			Val.put("StatusUpdate", StatusUpdate);
			Val.put("StatusDoc", StatusDoc);

			long rows = db.insert(TABLE_ServicePOSLists, null, Val);

			db.close();
			return rows; // return rows inserted.

		} catch (Exception e) {
			return -1;
		}

	}
	
	public long UpdateItemServicePOSLists(
			String ServicePOSListsOID,
			
			String Qty, 
			String Price,
			String TotalAmount,
			
			String Discount
		) {
		// TODO Auto-generated method stub

		try {
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			ContentValues Val = new ContentValues();
			Val.put("ServicePOSListsOID", ServicePOSListsOID);

			
			Val.put("Qty", Qty);
			Val.put("Price", Price);
			Val.put("TotalAmount", TotalAmount);
			
			Val.put("Discount", Discount);

//			long rows = db.insert(TABLE_ServicePOSLists, null, Val);	
			long rows = db.update(TABLE_ServicePOSLists, Val, " ServicePOSListsOID = ?",
					new String[] { String.valueOf(ServicePOSListsOID) });
			db.close();
			return rows; // return rows inserted.

		} catch (Exception e) {
			return -1;
		}

	}
	
	public long UpdateStatusServicePOSLists(
			String ServicePOSListsOID,
			
			String StatusUpdate,
			String StatusDoc
		) {
		// TODO Auto-generated method stub

		try {
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			ContentValues Val = new ContentValues();
			Val.put("ServicePOSListsOID", ServicePOSListsOID);
			
			if(!StatusUpdate.equals("")){
				Val.put("StatusUpdate", StatusUpdate);
			}
			if(!StatusDoc.equals("")){
				Val.put("StatusDoc", StatusDoc);
			}
			
//			long rows = db.insert(TABLE_ServicePOSLists, null, Val);	
			long rows = db.update(TABLE_ServicePOSLists, Val, " ServicePOSListsOID = ?",
					new String[] { String.valueOf(ServicePOSListsOID) });
			db.close();
			return rows; // return rows inserted.

		} catch (Exception e) {
			return -1;
		}

	}
	
	

	  
	  public long UpdatetoServer_POSLIST() throws Exception{
		  	ServicePOS pos = new ServicePOS();
	    	String data[][];
	    	Boolean insert = false;
	    	int length = 0;
	    	rs = null;
	    	try{
	    		data = SelectAll_ServicePOSList("", "0", "0");
	    		length = data.length;
	    		for(int i=0;i<length;i++){
	    				
//	    				pos.setParamDocNo(data[i][1]);
	    				pos.setParamPOSOID(data[i][0]);
	    				rs = pos.selectPOSLists();
	    				if(rs.next()){
	    					insert=false;
	    				}else{
	    					insert=true;
	    				}
	    				pos.setPOSListsOID(data[i][0]);
	    				pos.setUsrOpt(data[i][16]);
	    				pos.setIsActive("1");
	    				pos.setIsDeleted(data[i][20]);
	    				
	    				pos.setPOSOID(data[i][1]);
	    				pos.setItemOID(data[i][2]);
	    				pos.setQty(Integer.valueOf(data[i][3]));
	                    pos.setPrice(Double.valueOf(data[i][4]));
	                    pos.setTotalAmount(Double.valueOf(data[i][5]));
	                    
	                    pos.setUnitOID(data[i][8]);
	                    pos.setWHOID(data[i][9]);
	                    pos.setICZoneOID("");
	                    pos.setICStorageOID("");
	                    pos.setICShelfOID("");
//	                         
	                    pos.setICColumnOID(data[i][13]);
//	                    pos.setStkInOutDateTime(data[i][14]);
//	                    pos.setStatus(data[i][15]);
//	                    pos.setIsMove("0");
	                    pos.setDiscountAmount(Double.valueOf(data[i][6]));
//	                    
//	                    pos.setSerialNo("");
//	                    pos.setLotNo("");
//	                    pos.setRefOID(data[i][1]);
//	                    pos.setIsItemPromotionGiveaways("0");
//	                    pos.setIsItemPromotionSets("0");
	                    
	    			    if(insert == true){
	    			    	try {
	        					if(pos.stpPOSListsManagement("Insert") != null){
	        						long check = UpdateStatusServicePOSLists(	
	        										data[i][0],
													"1", 
													"");
	        						if(check<0){
	        							return -19;
	        						}
	        					}
	        				} catch (Exception e) {
	        					 return -12;
	        				}
	    			    }else{
	    			    	try {
	        					if(pos.stpPOSListsManagement("Update") != null){
	        						long check =UpdateStatusServicePOSLists(	
    										data[i][0],
											"1", 
											"");
	        						if(check<0){
	        							return -13;
	        						}
	        					}
	        				} catch (Exception e) {
	        					 return -14;
	        				}
	    			    }
	    		}
	    	}catch(Exception e){
	             return -15;
	    	}
	    	
			return 0;
	    }
	
}
